ecCompress Files collection

The ecCompress control has a Files collection that is used to specify which files should be included during the next Compress method.

Item (default), ItemByName

object.Files.Item(Index As Integer)
object.Files(Index As Integer)
object.Files.ItemByName(Filename As String)

The Item and ItemByName return an ecCompressFile object, based on either the file's index (starting at 1) or its filename. You can also use a For..Next loop to iterate through the file objects in this collection.

Count

object.Files.Count

The Count property returns the total number of file objects that are in the collection.

TotalSize

object.Files.TotalSize

The TotalSize property returns the total size of all of the files to be included in the cabinet. This is not the same as the size of the resulting cabinet file. This file will be smaller or larger, depending on the UseCompression property.

Add

object.Files.Add (Filename As String, CabFilename As String)

The Add method adds a file to the collection, and returns a reference to it. You may specify Filename, the full path to the file to be included, as well as CabFilename, the filename to save the file as in the cabinet. CabFilename may include path information in the form "Path\File", but this is not required.

AddFolder

object.Files.AddFolder (Folder As String, KeepPath As Boolean, KeepRoot As Boolean)

The AddFolder method adds the contents of a folder to the Files collection. You may also specify KeepPath and KeepRoot. KeepPath, which defaults to True, causes the path information to be saved into the cabinet for subfolders of Folder. KeepRoot, which defaults to False, causes the name of the original folder to also be saved to the cabinet.

Item.Filename (default), Item.CabFilename

fileobject.Filename = String
fileobject.CabFilename = String

The Filename and CabFilename properties are usually set in the Add method. Filename contains the actual filename to the source file to be included in the cabinet. CabFilename contains the name that is to be saved in the cabinet, such as "Path\File.ext".

Item.AutoRun

fileobject.AutoRun = Boolean

Each file in the Files collection has an AutoRun property. This property is not supported by most programs, but some programs will automatically open every file with the AutoRun property set to True once extraction is completed.

Example

The following code adds the entire contents of a folder to a new cabinet, adding a .TXT extension to all of the files in this folder. (No, this isn't something you'd ever do -- it's just for the example)

' Beginning of sample

Private Sub Command1_Click()
 Dim MyFile As ecCompressFile
    ecCompress1.FileName = "C:\Windows\Desktop\MyCab.cab"
    ecCompress1.Files.AddFolder "C:\Windows\Desktop\MyFolder"
    For Each MyFile In ecCompress1.Files
        MyFile.CabFilename = MyFile.CabFilename & ".txt"
    Next MyFile
    ecCompress1.Compress
End Sub

Private Sub ecCompress1_Progress(ByVal PercentDone As Integer)
    Label1.Caption = PercentDone & "% done..."
End Sub

' End of sample

See Also

Compress method, UseCompression property